﻿import urllib,urllib2,cookielib
#211.162.121.182
proxy_support = urllib2.ProxyHandler({'http':'127.0.0.1:8087'})

cook_jar=cookielib.CookieJar()
cookie_support=urllib2.HTTPCookieProcessor(cook_jar)
opener=urllib2.build_opener(proxy_support,cookie_support,urllib2.HTTPHandler)
urllib2.install_opener(opener)

user_agents = [
                'Mozilla/5.0 (Windows NT 5.1; rv:13.0) Gecko/20100101 Firefox/13.0.1',
                'Opera/9.25 (Windows NT 5.1; U; en)',
                'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
                'Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)',
                'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12',
                'Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9'
                ]

post_data=urllib.urlencode({'email':'dylinshi',
                               'passwd':'123456a',
                               'autologin':'on',
                               'reback':'http%3A%2F%2Fblog.51cto.com',
                               'button.x':'29',
                               'button.y':'13',
                               })

headers={
            'User-Agent':user_agents[0],
            'Accept-Language':'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3',
            #'Referer':'http://www.51cto.com/'
            }

url='http://blog.csdn.net/chief1985/article/month/2006/10'
#url='http://tzwzero-163-com.iteye.com/blog/1696490'
res = urllib2.urlopen(urllib2.Request(url,headers=headers))

if url.strip() == res.url.strip():                      #不保存重定向的网页
    data=res.read()
else:
    data=''
    print 'RRRR %s is a redirect page'%url
res.close()

print data

print 'end'


